<?php
class Adminshop extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('shop_model');
		
	}
	
	public function index()
	{
		$data['shop'] = $this->shop_model->get_shop();
		$data['title'] = 'Shop Config';

		$this->load->view('templates_admin/header', $data);
		$this->load->view('templates_admin/sidebar', $data);
		$this->load->view('pages_admin/shop_index', $data);
		$this->load->view('templates_admin/footer');
	}
	
	public function delete($id){		
		$deleted = $this->shop_model->delete($id);		
		$data['shop'] = $this->shop_model->get_shop();
		
		$this->load->view('templates_admin/header', $data);
		$this->load->view('templates_admin/sidebar', $data);
		$this->load->view('pages_admin/shop_index', $data);
		$this->load->view('templates_admin/footer');
	}
	
	public function create($id = FALSE){
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->library('form_validation');		
		$this->form_validation->set_error_delimiters('<h4 class="alert_info">', '</h4>');
		
		if ($id != FALSE){
			$data['data'] = $this->shop_model->get_shop($id);
			$data['title'] = 'Update ' . $data['data']['SHOP_NAME'];
		} else {
			$data['title'] = 'Add a new shop';
		}
		
		$this->form_validation->set_rules('shop_name', 'Nama Toko', 'required');
		$this->form_validation->set_rules('web_url', 'Web URL', 'required');
		$this->form_validation->set_rules('phone', 'Telepon', 'required');
		$this->form_validation->set_rules('phone_mobile', 'HP', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');
		$this->form_validation->set_rules('contact_person', 'Nama Pemilik', 'required');
		$this->form_validation->set_rules('acc_username', 'Username', 'required');
		$this->form_validation->set_rules('acc_password', 'Password', 'required');
		$this->form_validation->set_rules('acc_status', 'Status', 'required');
	
		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates_admin/header', $data);
			$this->load->view('templates_admin/sidebar', $data);
			$this->load->view('pages_admin/shop_form', $data);
			$this->load->view('templates_admin/footer');
		}
		else
		{
			$this->shop_model->set_shop();
			//$this->load->view('shopconfig/succes');
			redirect('shopconfig/', 'location', 301);
		}
	}
}
	
?>	